import os
from PIL import Image, ImageTk
from tkinter import ttk
import threading
import tkinter.messagebox as tm

from SubThread.AutoGridChara import AutoGridChara

from windows.SelectPane import SelectPane
from Main import Program
import QuetionPolicy.PoliyFactory as QuetionPoliyFactory
import windows.Exam as Exam
import Util.UserManager as UMF
import Util.WindowsUtil as Util
from windows.Scale import SuperScale, AUTOBIND_Operator
from windows.RadioBtn import *
from Util.InIManager import iniManager  as base_iniManger
from RememberWord import WordManager

# ---- V3.0
from  windows.SubWindows.CharaInfo import CharaInfo
from windows.SubWindows.WorryViewer import WorryViwer
from windows.SubWindows.TestMaker import TestMaker

UM = UMF.UserManager()
myUser = None  # 当前用户类

TestTypeList = [
    "A 全面测试", "B 专题测试", "C 错题回顾",
    "D 推荐测试(new)", "E 娱乐模式(new)",
    "F 固定模式(new)", "错题查看"
]

InfoTypeList = [
    "全面测试就是将所有的题杂糅在一起进行测试，是一种综合较强的模式",
    "专题测试就是对某一种类型的题进行抽查，如果你对某类考试薄弱可以通过这个方法进行测试",
    "对错题的一种全面的回顾",
    "对用户的喜好与易错点进行推荐抽查，旨在对每个用户的个性化",
    "(开发中)将养成类游戏与学习结合在一起的模式，寓教于乐",
    "(开发中)利用题型种子进行题的抽查，可以反复刷同一类型的题",
    "可以在在这里查看做错的题目"
]

import os
import tkinter as tk
from tkinter import messagebox as tm

from User.Code import User as User



class Event:
    @staticmethod
    def ChooseTypeQue(window, group):
        get = group.GetActiveId()
        if not get:
            tk.messagebox.showerror("错误", "你尚未选择任何题库!")
            return
        else:
            window.examWindowFront(f'专题测试--------{get}')

    @staticmethod
    def saveSetting(key, value):
        print(f"value={value}")
        exec(f"super_iniManager.saveDas({key}='{value}')")

    @staticmethod
    def reLogin(self):
        """
        重新登录按钮
        @param self: 窗口对象
        @return:
        """
        UM.logout()
        myUser = None
        self.win.destroy()
        a = windows()
        try:
            return a
        except:
            ...
        finally:
            a.Login()
            a.show()

    @staticmethod
    def Entry_clicked(widget, checkValue, isPwd=False):
        """
        Entry点击事件
        @param widget:
        @param checkValue:
        @param isPwd:
        @return:
        """
        if widget.get() == checkValue:
            print("清空")
            if isPwd: widget.config(show="*")
            widget.delete(0, tk.END)

    @staticmethod
    def Entry_leave(w, c, isPwd=False):
        """
        Entry leave事件
        @param w:
        @param c:
        @param isPwd:
        @return:
        """
        print("激活")
        if w.get() == "":
            if isPwd:
                w.config(show="")
            w.insert(0, c)

    @staticmethod
    def LoginAccount(window):
        """
        窗口登录事件
        @param window:
        @return:
        """
        username = window.entry_username.get()
        password = window.entry_password.get()
        validateRet = UM.vildate(username=username, password=password)
        if username == "username" and password == "password":
            tm.showerror("错误", "你还没有输入文本喲\r\n(无法使用username为账号的时候password为密码)")
            return

        if validateRet:
            # TODO 登录成功 记录登录状态
            UM.State = username
            myUser = User.MyUser(userName=username)
            tm.showinfo("提示", f"欢迎回来 {username} 今天也是元气满满的一天哟")
            window.user = username
            window.Menu()
        else:
            tm.showinfo("提示", f"eee 密码错误了")

    @staticmethod
    def RegAccount(window):
        username = window.entry_username.get()
        password = window.entry_password.get()
        if username == "username" and password == "password":
            tm.showerror("错误", "你不能将账号设置为username时密码作为password")
            return
        ret = UM.RegUser(username, password)
        if ret[0]:
            os.mkdir(f"./window_source/user/{username}")
            tm.showinfo("提示", f"注册成功了哟~~")
        else:
            tm.showerror("错误", ret[1])

    @staticmethod
    def ChageMoudle(self):
        self.entry_password.delete(0, tk.END)
        self.entry_password.insert(0, "password")
        self.entry_username.delete(0, tk.END)
        self.entry_username.insert(0, "username")

        self.entry_username.config(show="")
        self.entry_password.config(show="")

    @staticmethod
    def selectLight(self, place: tuple = (0, 0), status: str = "in"):
        if status == "in":
            self.init_widget()
            print(place)
            self.selectOptionLable.place(x=place[0], y=place[1], width=76, height=10)
            self.win.update()
        else:
            self.selectOptionLable.destroy()
class ManagerEnum:
    SettingInIManager = base_iniManger("Setting.ini")  # 设置配置文件的配置文件
    WordManager = WordManager.Manager()


class windows:

    def __init__(self):
        # region Field
        self.backLable = ...  # 背景
        self.backcolor = "#F0F0F0"  # 背景颜色
        self.backLableConfig = ...  # 背景色Config文件
        self.user = ...  # 默认用户
        # endregion

        self.win = tk.Tk()
        self.win.minsize(258,0)

        self.win.geometry("1200x600")
        self.win.resizable(False, False)
        self.win.title("刷题宝 " + Program.version)
        self.defaultColorTitleLable = '#FF00FF'

        # TODO 信息初始化
        self.init_image()
        self.init_widget()
        self.state="None" # 激活页

    def init_widget(self):
        self.selectOptionLable = tk.Label(self.win, image=self.Loge_OptionLight)

    def init_image(self):
        self.Loge_RemberWord = ImageTk.PhotoImage(Image.open(os.getcwd() + "/window_source/default.jpg"))
        self.O_Loge_RemberWord = Image.open(os.getcwd() + "/window_source/logo_RemenberWord.png")
        self.Loge_RemberWord = ImageTk.PhotoImage(self.O_Loge_RemberWord.resize((76, 76)))
        self.O_Loge_OptionLight = Image.open(os.getcwd() + "/window_source/select_light.png")
        self.Loge_OptionLight = ImageTk.PhotoImage(self.O_Loge_OptionLight.resize((76, 76)))
        self.O_Loge_gen_exam = Image.open(os.getcwd() + "/window_source/logo_gen_exam.png")
        self.Loge_OptionGenExam = ImageTk.PhotoImage(self.O_Loge_gen_exam.resize((76, 76)))
        self.O_Loge_setting = Image.open(os.getcwd() + "/window_source/setting.png")
        self.Loge_Setting = ImageTk.PhotoImage(self.O_Loge_setting.resize((76, 76)))
        self.O_CharaInfo = Image.open(os.getcwd() + "/window_source/charainfo.png")
        self.CharaInfo = ImageTk.PhotoImage(self.O_CharaInfo.resize((76, 76)))
        self.O_Exam = Image.open(os.getcwd() + "/window_source/exam.png")
        self.ExamPic = ImageTk.PhotoImage(self.O_Exam.resize((76, 76)))
        self.O_More = Image.open(os.getcwd() + "/window_source/more.png")
        self.MorePic = ImageTk.PhotoImage(self.O_More.resize((76, 76)))

        self.open_open = Image.open(os.getcwd() + "/window_source/Side/Open.png")
        self.pic_open = ImageTk.PhotoImage(self.open_open.resize((66, 66)))

        self.open_close = Image.open(os.getcwd() + "/window_source/Side/close.png")
        self.pic_close = ImageTk.PhotoImage(self.open_close.resize((66, 66)))

    def LoginBind(self):
        """
            登录界面 绑定
        :return:
        """
        self.entry_username.bind("<FocusIn>", lambda e: Event.Entry_clicked(self.entry_username, "username"))
        self.entry_password.bind("<FocusIn>", lambda e: Event.Entry_clicked(self.entry_password, "password", True))
        self.entry_username.bind("<FocusOut>", lambda e: Event.Entry_leave(self.entry_username, "username"))
        self.entry_password.bind("<FocusOut>", lambda e: Event.Entry_leave(self.entry_password, "password", True))

    def Reg2LoginMoveTask(self):
        """
        移动 注册到登录
        :return:
        """
        thread_new = threading.Thread(target=Util.Cartoon.Reg2Thread,
                                      args=(self.win, self.TitleFrame, self.FormFrame))
        thread_new.run()

        self.TitleLableConfig.Color = '#FF00FF'

        self.TitleTypeConfig.Color = '#FF00FF'
        self.TitleTypeConfig.Text = "  登  录  "

        self.TitleTypeConfigEnglish.Color = '#FF00FF'
        self.TitleTypeConfigEnglish.Text = "Login"

        Event.ChageMoudle(self)

        self.chageBtn.config(text="创建新号", command=self.Login2RegMoveTask)
        self.win.bind("<Return>", lambda a: Event.LoginAccount(self))
        self.OkayBtn.config(text="确认登录", command=lambda: Event.LoginAccount(self))  # TODO 登录

    def Login2RegMoveTask(self):
        """
        移动 登录到注册
        :return:
        """
        thread_new = threading.Thread(target=Util.Cartoon.ThreadLogin2Reg,
                                      args=(self.win, self.TitleFrame, self.FormFrame))
        thread_new.run()

        self.TitleLableConfig.Color = "Blue"

        self.TitleTypeConfig.Color = "Blue"
        self.TitleTypeConfig.Text = "  注  册  "

        self.TitleTypeConfigEnglish.Color = "Blue"
        self.TitleTypeConfigEnglish.Text = "Register"

        Event.ChageMoudle(self)

        self.chageBtn.config(text="老用户登录", command=self.Reg2LoginMoveTask)
        self.win.bind("<Return>", lambda a: Event.RegAccount(self))
        self.OkayBtn.config(text="确认注册", command=lambda: Event.RegAccount(self))  # TODO 注册

    def selectExam(self):
        """
        用户考试选择界面
        @return:
        """
        self.window2ExamSelect()

    def rememberWord(self):
        """
        背单词模块
        @return:
        """
        self.Login2Menu(True)
        # TODO 背单词模块
        self.state = "背单词"
        ManagerEnum.WordManager.win = self.win
        ManagerEnum.WordManager.wino = self
        ManagerEnum.WordManager.start()

    def examWindowFront(self, module):
        """
        考试界面前置
        @param module: 出题工厂参数
            如果为 专题测试 那么程序会提示用户选择专题
            选择之后会递归examWindow module参数会成为 专题测试--------XX专题

        """
        self.Login2Menu(True)
        # TODO 考试界面开发


        # region  考试信息获取
        ManagerEnum.SettingInIManager = base_iniManger("Setting.ini")  # 刷新管理器
        count_question = int(ManagerEnum.SettingInIManager.getValue("Setting", "QuestionCount"))
        time_second = int(ManagerEnum.SettingInIManager.getValue("Setting", "AskTime"))
        self.user_key = []  # 用户填写答案列表
        self.true_key = []  # 正确答案列表
        self.que_index = []  # 当前考试题目索引

        # endregion

        # region 题库获取
        if module == '专题测试':
            Group = RadioGroup()
            FileList = os.listdir('./TestBank')
            self.TitleLable_Setting = WidgetConfig.WidgetConfig("#2B2B2B", tk.Label(self.win, fg='white'), "题库选择",
                                                                Util.Font(self.win).Title)
            self.TitleLable_Setting.initFont()
            self.TitleLable_Setting = self.TitleLable_Setting.getWidget()
            self.TitleLable_Setting.place(relwidth=1, relx=0, y=120)

            row = 0
            col = 0
            lf = tk.LabelFrame(self.win)
            lf.place(relx=0.15, y=200, relheight=0.5)
            # TODO  这里可以设置分页
            for i in FileList:
                if col % 2 == 1:
                    A = Box('#87CEEB', 'white', i.replace(".csv", ''), "#2B2B2B",
                            "white", Group, i, lf, "xx",
                            False).getLabel()
                else:
                    A = Box('white', '#2B2B2B', i.replace(".csv", ''), "#363B40",
                            "white", Group, i, lf, "xx",
                            False).getLabel()
                A['width'] = 30
                A['height'] = 3
                A.grid_columnconfigure(0, weight=1, uniform="fred")
                A.grid(row=row, column=col)
                col += 1
                if col > 3:
                    col = 0
                    row += 1
            button = ttk.Button(self.win, text='就这个了!')
            button.bind("<Button-1>", lambda e: Event.ChooseTypeQue(self, Group))
            button.place(relx=.45, y=540, width=150, height=50)
            return
        elif "专题测试" in module:
            print(module.split("--------"))
            module, QuePack = module.split("--------")
            self.QueList = QuetionPoliyFactory.Factory.Generate(module, QuePack, many=count_question)
        elif module == "错题回顾":
            self.QueList = QuetionPoliyFactory.Factory.Generate(module, self.user, many=count_question)
        else:
            self.QueList = QuetionPoliyFactory.Factory.Generate(module, many=count_question)
        # endregion

        print(f"self.QueList:{self.QueList}")
        if self.QueList == []:
            tm.showerror("错误", "无题类型题库")
            self.Login2Menu()
            return
        tm.showinfo("开始考试", "练习开始了哟 ~")
        Exam.WindowsExam(self.win, QueList=self.QueList, User=self.user, Time=time_second)

    def window2Setting(self):
        """
        任意界面 ——> 设置窗口
        @return:
        """
        base_x = 300
        self.state = "设置"
        ManagerEnum.SettingInIManager = base_iniManger("Setting.ini")  # 刷新管理器
        QuestionCount = int(ManagerEnum.SettingInIManager.getValue("Setting", "QuestionCount"))
        AskTime = int(ManagerEnum.SettingInIManager.getValue("Setting", "AskTime"))
        WordCount = int(ManagerEnum.SettingInIManager.getValue("Setting", 'WordCount'))
        print(QuestionCount)
        print(AskTime)
        print(WordCount)
        self.Login2Menu(True)
        self.TitleLable_Setting = WidgetConfig.WidgetConfig("#2B2B2B", tk.Label(self.win, fg='white'), "程序设置",
                                                            Util.Font(self.win).Title)
        self.TitleLable_Setting.initFont()
        self.TitleLable_Setting = self.TitleLable_Setting.getWidget()
        self.TitleLable_Setting.place(relwidth=1, relx=0, y=120)

        # --------- 出题数目
        tmp = WidgetConfig.WidgetConfig("#2B2B2B", tk.Label(self.win, fg='white'), "出题数目",
                                        Util.Font(self.win).Text)
        tmp.initFont()
        tmp.getWidget().place(width=120, relx=0.3, rely=0.34)

        Manager = SuperScale(self.win, 1, 400, "#363B40", "white", True, "red", default=QuestionCount)
        CountTestWid = Manager.getContainer()
        CountTestWid.place(relx=0.5, rely=0.35)

        # --------- 倒计时
        tmp2 = WidgetConfig.WidgetConfig("#2B2B2B", tk.Label(self.win, fg='white'), " 计时器单位秒 ",
                                         Util.Font(self.win).Text)
        tmp2.initFont()
        tmp2.getWidget().place(width=120, relx=0.3, rely=0.42)

        TimeManager = SuperScale(self.win, 1, 18000, "#363B40", "white", True, "red", default=AskTime)
        TimeWid = TimeManager.getContainer()
        TimeWid.place(relx=0.5, rely=0.43)

        tmp3 = WidgetConfig.WidgetConfig("#2B2B2B", tk.Label(self.win, fg='white'), " 单词记忆数",
                                         Util.Font(self.win).Text)
        tmp3.initFont()
        tmp3.getWidget().place(width=120, relx=0.3, rely=0.50)

        WordManager = SuperScale(self.win, 1, 100, "#363B40", "white", True, "red", default=WordCount)
        WordWid = WordManager.getContainer()
        WordWid.place(relx=0.5, rely=0.51)

        # TODO 事件绑定区域

        Manager.BindChage(Event.saveSetting, ('queCount', AUTOBIND_Operator.AUTO_VALUE))
        TimeManager.BindChage(Event.saveSetting, ('timeExam', AUTOBIND_Operator.AUTO_VALUE))
        WordManager.BindChage(Event.saveSetting, ('wordCount', AUTOBIND_Operator.AUTO_VALUE))

    def window2ExamSelect(self):
        """
        任意界面 ——> 考试选择切换
        @return:
        """
        self.state = "考试"
        methodList = \
            [
                lambda e: exam('全面测试', self),
                lambda e: exam('专题测试', self),
                lambda e: exam('错题回顾', self),
                lambda e: exam('推荐测试', self),
                lambda e: print("xxx", self),
                lambda e: print("xxx", self),
                lambda e: WorryViwer(self)

            ]

        def exam(val, w):
            w.examWindowFront(val)

            # print("Value" + value)

        self.Login2Menu(True)
        self.TitleLable_ExamSelect = WidgetConfig.WidgetConfig("#2B2B2B", tk.Label(self.win, fg='white'), "选择学习项目",
                                                               Util.Font(self.win).Title)
        self.TitleLable_ExamSelect.initFont()
        self.TitleLable_ExamSelect = self.TitleLable_ExamSelect.getWidget()
        self.TitleLable_ExamSelect.place(relwidth=1, x=0, y=120)
        self.TitleLable_ExamSelect.place(relwidth=1, x=0, y=120)
        # TODO 选择SelectPane窗口搭建
        self.PaneExamTypeChoose = SelectPane(titleList=TestTypeList, infoList=InfoTypeList,
                                             method=methodList,
                                             background_color="#3C3F41", font_color="white",
                                             win=self.win, subtitleFont=("华文中宋", 14), titleFont=("华文中宋", 19))
        self.Container = self.PaneExamTypeChoose.getContainer()
        self.Container.place(relx=0, y=210, relwidth=1, height=300)

    def Login(self):
        """
        登录界面
        :return:
        """

        self.TitleFrame = ttk.Frame(self.win)
        self.TitleFrame.place(x=0, y=0, width=600, height=600)

        self.TitleLableConfig = WidgetConfig.WidgetConfig(self.defaultColorTitleLable, tk.Label(self.TitleFrame))
        self.TitleLable = self.TitleLableConfig.getWidget()
        self.TitleLable.place(x=0, y=0, width=600, height=600)

        self.TitleTypeConfig = WidgetConfig.WidgetConfig(self.defaultColorTitleLable,
                                                         tk.Label(self.TitleFrame, fg="white"),
                                                         "  登  录  ",
                                                         Util.Font(self.win).H1)
        self.TitleTypeConfig.initFont()
        self.TitleTypeLable = self.TitleTypeConfig.getWidget()
        self.TitleTypeLable.place(x=170, y=200)

        self.TitleTypeConfigEnglish = WidgetConfig.WidgetConfig(self.defaultColorTitleLable,
                                                                tk.Label(self.TitleFrame, fg="white"),
                                                                "Login",
                                                                Util.Font(self.win).H2_En)
        self.TitleTypeConfigEnglish.initFont()
        self.TitleTypeLableEnglish = self.TitleTypeConfigEnglish.getWidget()
        self.TitleTypeLableEnglish.place(x=260, y=290)

        # region 登陆侧
        self.FormFrame = ttk.Frame(self.win, )

        self.FormFrame.place(x=600, y=0, width=600, height=600)
        y = 10
        tk.Label(self.FormFrame, text="", bg='white').place(x=0, y=0, width=600, height=600)

        tk.Label(self.FormFrame, text="刷题宝", font=Util.Font(self.win).Title, bg='white').place(x=100, y=y + 100,
                                                                                               width=400,
                                                                                               height=50)

        self.entry_username = ttk.Entry(self.FormFrame, font=Util.Font(self.win).input)
        self.entry_username.insert(0, "username")
        self.entry_username.place(x=100, y=y + 200, width=400, height=50)

        self.entry_password = ttk.Entry(self.FormFrame, font=Util.Font(self.win).input)
        self.entry_password.insert(0, "password")
        self.entry_password.place(x=100, y=y + 300, width=400, height=50)

        self.chageBtn = ttk.Button(self.FormFrame, text="创建新号", command=self.Login2RegMoveTask)
        self.chageBtn.place(x=100, y=y - 10 + 400, width=160, height=50)

        self.OkayBtn = ttk.Button(self.FormFrame, text="登录账号", command=lambda: Event.LoginAccount(self))
        self.OkayBtn.place(x=340, y=y - 10 + 400, width=160, height=50)
        # endregion
        self.win.bind("<Return>", lambda a: Event.LoginAccount(self))

        self.LoginBind()

    def _(self):
        self.state = "图鉴"
        print("HelloWorld")
        self.thread_agc = AutoGridChara(self)
        self.thread_agc.openThread()



        CharaInfo(self)

    def Login2Menu(self, option=False):
        """
        过渡 放置基本UI
        @param option 是否关闭动画
        :return:
        """
        if not option:
            self.win.resizable(True, True)
            self.OkayBtn.destroy()
            self.chageBtn.destroy()

            self.SelectLightWidget = tk.Label()

            t1 = threading.Thread(target=Util.Cartoon.Login2Menu, args=(self,))
            t1.run()
        else:
            self.win.backLableConfig = WidgetConfig.WidgetConfig("#2B2B2B", tk.Label(self.win, fg="#000000"))
            self.win.backLable = self.win.backLableConfig.getWidget()
            self.win.backLable.place(x=0, y=0, relwidth=1, relheight=1)
        self.headMenu = tk.Label(self.win, bg="#3C3F41")
        self.headMenu.place(x=0, y=0, relwidth=1, height=100)

        self.backLableConfig.Color = "#2B2B2B"

        y = 50
        base = 0.125
        self.Lable_remberWord = tk.Label(self.win, image=self.Loge_RemberWord, cursor="hand2")
        self.Lable_remberWord.place(relx=base*1, y=20, width=76, height=76)

        self.Lable_genExam = tk.Label(self.win, image=self.Loge_OptionGenExam, cursor="hand2")
        self.Lable_genExam.place(relx=base*2, y=20, width=76, height=76)

        self.Lable_Setting = tk.Label(self.win, image=self.Loge_Setting, cursor="hand2")
        self.Lable_Setting.place(relx=base*3, y=20, width=76, height=76)

        self.Lable_charaInfo = tk.Label(self.win, image=self.CharaInfo, cursor="hand2")
        self.Lable_charaInfo.place(relx=base*4, y=20, width=76, height=76)

        self.Lable_exam = tk.Label(self.win, image=self.ExamPic, cursor="hand2")
        self.Lable_exam.place(relx=base*5, y=20, width=76, height=76)

        self.Lable_more = tk.Label(self.win, image=self.MorePic, cursor="hand2")
        self.Lable_more.place(relx=base*6, y=20, width=76, height=76)

        # TODO 事件绑定区
        self.Lable_remberWord.bind("<Enter>", lambda e: Event.selectLight(self, (self.win.winfo_width() * base * 1, 0)))
        self.Lable_remberWord.bind("<Leave>", lambda e: Event.selectLight(self, (99999, 99999), "out"))
        self.Lable_remberWord.bind("<Button-1>", lambda e: self.rememberWord())

        self.Lable_genExam.bind("<Enter>", lambda e: Event.selectLight(self, (self.win.winfo_width() * base * 2, 0)))
        self.Lable_genExam.bind("<Leave>", lambda e: Event.selectLight(self, (99999, 99999), "out"))
        # TODO 事件
        self.Lable_genExam.bind("<Button-1>", lambda e: TestMaker(self))


        self.Lable_Setting.bind("<Enter>", lambda e: Event.selectLight(self, (self.win.winfo_width() * base * 3, 0)))
        self.Lable_Setting.bind("<Leave>", lambda e: Event.selectLight(self, (99999, 99999), "out"))
        self.Lable_Setting.bind("<Button-1>", lambda e: self.window2Setting())


        self.Lable_charaInfo.bind("<Enter>", lambda e: Event.selectLight(self, (self.win.winfo_width() * base * 4, 0)))
        self.Lable_charaInfo.bind("<Leave>", lambda e: Event.selectLight(self, (99999, 99999), "out"))
        self.Lable_charaInfo.bind("<Button-1>", lambda e: self._())


        self.Lable_exam.bind("<Enter>", lambda e: Event.selectLight(self, (self.win.winfo_width() * base * 5, 0)))
        self.Lable_exam.bind("<Leave>", lambda e: Event.selectLight(self, (99999, 99999), "out"))
        self.Lable_exam.bind("<Button-1>", lambda e: self.window2ExamSelect())

        self.Lable_more.bind("<Enter>", lambda e: Event.selectLight(self, (self.win.winfo_width() * base * 6, 0)))
        self.Lable_more.bind("<Leave>", lambda e: Event.selectLight(self, (99999, 99999), "out"))
        self.Lable_more.bind("<Button-1>", lambda e: self.window2ExamSelect())

        self.win.bind("<Return>", lambda a: ...)  # 取消回车键

        # TODO 菜单栏
        self.MenuBar = tk.Menu(self.win)

        self.win.config(menu=self.MenuBar)

        self.fileBar = tk.Menu(self.MenuBar, tearoff=0, bg="#2B2B2B", fg="white", border=0)
        self.personalCenter = tk.Menu(self.MenuBar, tearoff=0, bg="#2B2B2B", fg="white")
        self.Chara = tk.Menu(self.MenuBar, tearoff=0, bg="#2B2B2B", fg="white")
        self.FastCommand = tk.Menu(self.MenuBar, tearoff=0, bg="#2B2B2B", fg="white")
        import sys


        self.fileBar.add_command(label="程序退出", command=lambda: sys.exit(0))
        self.fileBar.add_command(label="重新登录", command=lambda: Event.reLogin(self))
        self.fileBar.add_command(label="回到主菜单", command=lambda: self.Menu())

        self.personalCenter.add_command(label="能力雷达图及信息查看", command=lambda: sys.exit(0))
        self.personalCenter.add_command(label="角色一览", command=lambda: Event.reLogin(self))
        self.personalCenter.add_command(label="修改账号", command=lambda: Event.reLogin(self))
        self.personalCenter.add_command(label="永久删除账号", command=lambda: Event.reLogin(self))
        # self.FastCommand.add_command(label="", command=lambda: Event.reLogin(self))

        self.Chara.add_command(label="抽取角色", command=lambda: sys.exit(0))
        self.Chara.add_command(label="购买角色", command=lambda: Event.reLogin(self))
        self.Chara.add_command(label="商店", command=lambda: Event.reLogin(self))

        self.FastCommand.add_command(label="考试 -> 全部综合测试")
        self.FastCommand.add_command(label="考试 -> 单元测试")
        self.FastCommand.add_command(label="考试 -> 错题回顾测试")
        self.FastCommand.add_command(label="考试 -> 单词记忆模式")

        self.win.config(menu=self.MenuBar)

        self.MenuBar.add_cascade(label="程序", menu=self.fileBar)
        self.MenuBar.add_cascade(label="个人中心", menu=self.personalCenter)
        self.MenuBar.add_cascade(label="角色|购物", menu=self.Chara)

    def Menu(self):
        """
        主菜单
        :return:
        """
        self.win.state = "主菜单"
        self.Login2Menu()  # 放置导航控件
        self.state = "主菜单" # 当前状态激活页面是主菜单

        # self.bg = tk.Label(bg="red")
        # self.bg.place(relx=0, rely=100, relwidth=1, relheight=1)
        self.TitleLable_Toast = WidgetConfig.WidgetConfig("#2B2B2B", tk.Label(self.win, fg='white'), "公告",
                                                          Util.Font(self.win).Title)
        self.TitleLable_Toast.initFont()  # 设置字体

        # self.TitleLable_Toast.Color = "White"
        self.TitleLable_Toast_Lable = self.TitleLable_Toast.getWidget()
        self.TitleLable_Toast_Lable.place(relwidth=1, x=0, y=120)
        self.TitleLable_Toast = WidgetConfig.WidgetConfig("#2B2B2B", tk.Label(self.win, fg='white'),
                                                          open(r"./window_source/Totas.txt", 'r',
                                                               encoding="utf-8").read(),
                                                          Util.Font(self.win).Text)
        self.TitleLable_Toast.initFont()  # 设置字体
        List_Image = {"close":self.pic_close, "open":self.pic_open}

        # self.TitleLable_Toast.Color = "White"
        self.TitleLable_Toast_Lable = self.TitleLable_Toast.getWidget()
        self.TitleLable_Toast_Lable.place(relwidth=1, x=0, y=200)
        x = 330
        self.word_btn = tk.Button(self.win, bg='#FFCD22', text='单词记忆模式', command=self.rememberWord)
        self.word_btn['font'] = Util.Font(self.win).Text_3
        # self.word_btn.place(x=x,y=500,width=60*4,height=30*3)
        self.word_btn.place(relx=0.2, y=500, width=60 * 4, height=30 * 3)

        self.word_btn = tk.Button(self.win, bg='#FFCD22', text='考试模式', command=self.selectExam)
        self.word_btn['font'] = Util.Font(self.win).Text_3
        # self.word_btn.place(x=self.win.winfo_width()-60*4-x, y=500, width=60 * 4, height=30 * 3)
        self.word_btn.place(relx=0.6, y=500, width=60 * 4, height=30 * 3)

    def show(self):
        """
        显示窗口
        @return:
        """
        self.win.mainloop()
